package com.transaction;

import java.sql.*;

public class Transaction2 {
    public static void main(String[] args) throws SQLException {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        Connection conn =
                DriverManager.getConnection("jdbc:mysql://localhost:3306/manger", "root", "");
// JDBC中调用存储过程 CallableStatement
// CallableStatement callableStatement = conn.prepareCall("{callcal_salary(?)}");
        // callableStatement.setInt(1, 7788);
// ResultSet resultSet = callableStatement.executeQuery();
// if (resultSet.next()) {
// System.out.println(resultSet.getObject(1));
// }

        CallableStatement callableStatement = conn.prepareCall("{call `proc_while`(?)}");
        callableStatement.setInt(1, 10);
        ResultSet resultSet = callableStatement.executeQuery();
        if (resultSet.next()){
            System.out.println(resultSet.getObject(1));
        }
//        callableStatement.setInt(2, 4);
// 注入 OUT类型的参数 registerOutParameter(, 类型)
//        callableStatement.registerOutParameter(2, Types.INTEGER);
//        callableStatement.execute();
// getXXX(3)
//        int sum = callableStatement.getInt(1);
//        System.out.println(sum);
    }
}
